package com.platform.data.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 日期处理
 *
 * @author zhuweijun
 * @version 1.0.0
 * @since 2025/5/13 17:06
 */
public class DateUtils {

    public static final String DEFAULT_YYYY_MM_DD = "yyyy-MM-dd";

    public static final String DEFAULT_YYYYMMDD = "yyyyMMdd";

    public static final String DEFAULT_SLASH_YYYYMMDD = "yyyy/MM/dd";

    /**
     * 字符串转日期
     *
     * @param dateString dateString
     * @param patten patten
     * @return {@link Date}
     */
    public static Date stringToDate(String dateString, String patten) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(patten);
        LocalDate localDate = LocalDate.parse(dateString, formatter);
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());

    }


    /**
     * 日期转换字符串
     *
     * @param date date
     * @param patten patten
     * @return {@link String}
     */
    public static String getDateTime(Date date, String patten) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(patten);
        return dateFormat.format(date);
    }

}
